package com.geek.water.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.geek.water.entity.Bill;
import com.geek.water.vo.CustomerVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface BillMapper extends BaseMapper<Bill> {

    /**
     * 根据客户ID列表查询客户信息
     * @param customerIds 客户ID列表
     * @return 客户信息列表
     */
    @Select("<script>" +
            "SELECT id, name, credit_code as creditCode, status " +
            "FROM customer " +
            "WHERE id IN " +
            "<foreach collection='customerIds' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    List<CustomerVO> getCustomerInfoByIds(@Param("customerIds") List<Long> customerIds);

    /**
     * 通过账单编号查询账单信息
     * @param billCode 账单编号
     * @return 账单信息
     */
    @Select("SELECT * FROM bill WHERE bill_code = #{billCode}")
    Bill getBillByBillCode(@Param("billCode") String billCode);

    /**
     * 根据客户ID和计费周期查询账单
     * @param customerId 客户ID
     * @param billingPeriod 计费周期
     * @return 账单信息
     */
    @Select("SELECT * FROM bill WHERE customer_id = #{customerId} AND billing_period = #{billingPeriod}")
    Bill getBillByCustomerAndPeriod(@Param("customerId") Long customerId, @Param("billingPeriod") String billingPeriod);
}